import request from '@/utils/request'

export function login(data) {
  return request({
    url: '/login',
    method: 'post',
    params: data
  })
}

export function getInfo(token) {
  return request({
    url: '/login/user-info',
    method: 'get'
  })
}

export function getInfoRoute() {
  return request({
    url: '/login/user-route',
    method: 'get'
  })
}

export function logout() {
  return request({
    url: '/logout',
    method: 'post'
  })
}

// =====账号操作

export function addUser(user) {
  return request({
    url: '/user/add',
    method: 'post',
    params: user
  })
}

export function deleteUser(id) {
  return request({
    url: '/user/delete',
    method: 'delete',
    params: { id }
  })
}

export function modifyUser(user) {
  return request({
    url: '/user/modify',
    method: 'post',
    params: user
  })
}
export function pageUser(query, queryForm, orgId, isShowNoOrgUser) {
  var params = Object.assign(query, queryForm)
  params.organizationId = orgId
  params.isShowNoOrgUser = isShowNoOrgUser
  return request({
    url: '/user/page',
    method: 'get',
    params: params
  })
}

export function detailUser(id) {
  return request({
    url: '/user/detail',
    method: 'post',
    params: {
      id
    }
  })
}

export function resetPasswordUser(id, newPassword) {
  return request({
    url: '/user/reset-password',
    method: 'post',
    params: {
      id,
      newPassword
    }
  })
}

export function getUserRole(userId) {
  return request({
    url: '/user/user-role',
    method: 'get',
    params: {
      userId
    }
  })
}

export function saveUserRole(userId, roles) {
  return request({
    url: '/user/set-user-role',
    method: 'post',
    data: {
      userId,
      roles
    }
  })
}
